package br.mercadofacil.app.hma;




import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class Lista_Utilidades extends Activity{
	
	private SharedPreferences prefs;
	private final Handler mTwitterHandler = new Handler();
	private TextView loginStatus;
	
	final Runnable mUpdateTwitterNotification = new Runnable() {
		
		public void run() {
			// TODO Auto-generated method stub
			Toast.makeText(getBaseContext(), "Tweet Enviado", Toast.LENGTH_SHORT).show();
			
		}
	};
	
	String CopoDescartavel="";
	String Esponja="";
	String EsponjadeAco="";
	String FilmePlastico="";
	String FiltroCafe="";
	String Flanela="";
	String Fosforo="";
	String Guardanapo="";
	String Lampada="";
	String Luvas="";
	String Pa="";
	String Palito="";
	String PanodeChao="";
	String PapelAluminio="";
	String PapelToalha="";
	String Rodo="";
	String SacodeLixo="";
	String Vassoura="";
	String Vela="";
	String PanodePrato="";
	
	
	
	private CheckBox chbCopoDescartavel,chbEsponja,chbEsponjadeAco,chbFilmePlastico,chbFiltroCafe,chbFlanela,
	chbFosforo,chbGuardanapo,chbLampada,chbLuvas,chbPa,chbPalito,chbPanodeChao,chbPapelAluminio,chbPapelToalha,
	chbRodo,chbSacodeLixo,chbVassoura,chbVela,chbPanodePrato;
	
	public static final String PREFS_NAME = "SharedPrefsDemoPreferences";
	private SharedPreferences mPrefs;
	
	public static final String PREF_BOOL137 = "PrefBool137";
	public static final String PREF_BOOL138 = "PrefBool138";
	public static final String PREF_BOOL139 = "PrefBool139";
	public static final String PREF_BOOL140 = "PrefBool140";
	public static final String PREF_BOOL141 = "PrefBool141";
	public static final String PREF_BOOL142 = "PrefBool142";
	public static final String PREF_BOOL143 = "PrefBool143";
	public static final String PREF_BOOL144 = "PrefBool144";
	public static final String PREF_BOOL145 = "PrefBool145";
	public static final String PREF_BOOL146 = "PrefBool1146";
	public static final String PREF_BOOL147 = "PrefBool1147";
	public static final String PREF_BOOL148 = "PrefBool148";
	public static final String PREF_BOOL149 = "PrefBool149";
	public static final String PREF_BOOL150 = "PrefBool150";
	public static final String PREF_BOOL151 = "PrefBool151";
	public static final String PREF_BOOL152 = "PrefBool152";
	public static final String PREF_BOOL153 = "PrefBool153";
	public static final String PREF_BOOL154 = "PrefBool154";
	public static final String PREF_BOOL155 = "PrefBool155";
	public static final String PREF_BOOL156 = "PrefBool156";
	
	ImageButton btnPagina8;
	
	
	public static Object levaCopoDescartavel;
	public static Object LevaEsponja;
	public static Object LevaEsponjadeAco;
	public static Object LevaFilmePlastico;
	public static Object LevaFiltroCafe;
	public static Object LevaFlanela;
	public static Object LevaFosforo;
	public static Object LevaGuardanapo;
	public static Object LevaLampada;
	public static Object LevaLuvas;
	public static Object LevaPa;
	public static Object LevaPalito;
	public static Object LevaPanodeChao;
	public static Object LevaPapelAluminio;
	public static Object LevaPappelToalha;
	public static Object LevaRodo;
	public static Object LevaSacodeLixo;
	public static Object LevaVassoura;
	public static Object LevaVela;
	public static Object LevaPanodePrato;
	
	
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aba_utilidades);
		
		this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
		
		
	   
		AdView adView6 = (AdView)this.findViewById(R.id.adView6);  
		adView6.loadAd(new AdRequest());
		
		mPrefs = getSharedPreferences(PREFS_NAME, 0);
		
		chbCopoDescartavel = (CheckBox) findViewById(R.id.checkBoxCopoDescartavel);
		chbEsponja = (CheckBox) findViewById(R.id.checkBoxEsponja);
		chbEsponjadeAco = (CheckBox) findViewById(R.id.checkBoxEsponjadeAco);
		chbFilmePlastico = (CheckBox) findViewById(R.id.checkBoxFilmePlastico);
		chbFiltroCafe = (CheckBox) findViewById(R.id.checkBoxFiltroCafe);
		chbFlanela = (CheckBox) findViewById(R.id.checkBoxFlanela);
		chbFosforo = (CheckBox) findViewById(R.id.checkBoxFosforo);
		chbGuardanapo = (CheckBox) findViewById(R.id.checkBoxGuardanapo);
		chbLampada = (CheckBox) findViewById(R.id.checkBoxLampada);
		chbLuvas = (CheckBox) findViewById(R.id.checkBoxLuvas);
		chbPa = (CheckBox) findViewById(R.id.checkBoxPa);
		chbPalito = (CheckBox) findViewById(R.id.checkBoxPalito);
		chbPanodeChao = (CheckBox) findViewById(R.id.checkBoxPanodeChao);
		chbPanodePrato = (CheckBox) findViewById(R.id.checkBoxPanodePrato);
		chbPapelAluminio = (CheckBox) findViewById(R.id.checkBoxPapelAluminio);
		chbPapelToalha = (CheckBox) findViewById(R.id.checkBoxPapelToalha);
		chbRodo = (CheckBox) findViewById(R.id.checkBoxRodo);
		chbSacodeLixo = (CheckBox) findViewById(R.id.checkBoxSacodeLixo);
		chbVassoura = (CheckBox) findViewById(R.id.checkBoxVassoura);
		chbVela = (CheckBox) findViewById(R.id.checkBoxVela);
		
		btnPagina8 = (ImageButton) findViewById(R.id.btnGeraLista);
		
		btnPagina8.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				if (chbCopoDescartavel.isChecked()) {
					CopoDescartavel = "Copo Descartavel";

				}
				if (chbEsponja.isChecked()) {
					Esponja = "Esponja";

				}
				if (chbEsponjadeAco.isChecked()) {
					EsponjadeAco = "Esponja de A�o";

				}
				if (chbFilmePlastico.isChecked()) {
					FilmePlastico = "Filme Plastico";

				}
				if (chbFiltroCafe.isChecked()) {
					FiltroCafe = "Filtro de CafŽ";

				}
				if (chbFlanela.isChecked()) {
					Flanela = "Flanela";

				}
				if (chbFosforo.isChecked()) {
					Fosforo = "Fosoforo";

				}
				if (chbGuardanapo.isChecked()) {
					Guardanapo = "Guardanapo";

				}
				if (chbLampada.isChecked()) {
					Lampada = "Lampada";

				}
				if (chbLuvas.isChecked()) {
					Luvas = "Luvas";

				}
				if (chbPa.isChecked()) {
					Pa = "Pa";

				}
				if (chbPalito.isChecked()) {
					Palito = "Palito";

				}
				if (chbPanodeChao.isChecked()) {
					PanodeChao = "Pano de Ch‹o";

				}
				if (chbPanodePrato.isChecked()) {
					PanodePrato = "Pano de Prato";

				}
				if (chbPapelAluminio.isChecked()) {
					PapelAluminio = "Papel Aluminio";

				}
				if (chbPapelToalha.isChecked()) {
					PapelToalha = "Papel Toalha";

				}
				if (chbRodo.isChecked()) {
					Rodo = "Rodo";

				}
				if (chbSacodeLixo.isChecked()) {
					SacodeLixo = "Saco de Lixo";

				}
				if (chbVassoura.isChecked()) {
					Vassoura = "Vassoura";

				}
				if (chbVela.isChecked()) {
					Vela = "Vela";

				}
				
				levaCopoDescartavel=CopoDescartavel;
				LevaEsponja=Esponja;
				LevaEsponjadeAco=EsponjadeAco;
				LevaFilmePlastico=FilmePlastico;
				LevaFiltroCafe=FiltroCafe;
				LevaFlanela=Flanela;
				LevaFosforo=Fosforo;
				LevaGuardanapo=Guardanapo;
				LevaLampada=Lampada;
				LevaLuvas=Luvas;
				LevaPa=Pa;
				LevaPalito=Palito;
				LevaPanodeChao=PanodeChao;
				LevaPanodePrato=PanodePrato;
				LevaPapelAluminio=PapelAluminio;
				LevaPappelToalha=PapelToalha;
				LevaRodo=Rodo;
				LevaSacodeLixo=SacodeLixo;
				LevaVassoura=Vassoura;
				LevaVela=Vela;
				
				startActivity(new Intent(Lista_Utilidades.this, MostraLista.class));
				
			}
		});
		
		Button tweet = (Button)findViewById(R.id.tweet);
		
		
		tweet.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (TwitterUtils.isAuthenticated(prefs)) {
            		sendTweet();
            	} else {
    				Intent i = new Intent(getApplicationContext(), PrepareRequestTokenActivity.class);
    				startActivity(i);
            	}
				
				
				
				
				
			}
		});

}
	
	
	
	
	@Override
	protected void onResume() {

		
		chbCopoDescartavel.setChecked(mPrefs.getBoolean(PREF_BOOL137, false));
		chbEsponja.setChecked(mPrefs.getBoolean(PREF_BOOL138, false));
		chbEsponjadeAco.setChecked(mPrefs.getBoolean(PREF_BOOL139, false));
		chbFilmePlastico.setChecked(mPrefs.getBoolean(PREF_BOOL140, false));
		chbFiltroCafe.setChecked(mPrefs.getBoolean(PREF_BOOL141, false));
		chbFlanela.setChecked(mPrefs.getBoolean(PREF_BOOL142, false));
		chbFosforo.setChecked(mPrefs.getBoolean(PREF_BOOL143, false));
		chbGuardanapo.setChecked(mPrefs.getBoolean(PREF_BOOL144, false));
		chbLampada.setChecked(mPrefs.getBoolean(PREF_BOOL145, false));
		chbLuvas.setChecked(mPrefs.getBoolean(PREF_BOOL146, false));
		chbPa.setChecked(mPrefs.getBoolean(PREF_BOOL147, false));
		chbPalito.setChecked(mPrefs.getBoolean(PREF_BOOL148, false));
		chbPanodeChao.setChecked(mPrefs.getBoolean(PREF_BOOL149, false));
		chbPanodePrato.setChecked(mPrefs.getBoolean(PREF_BOOL150, false));
		chbPapelAluminio.setChecked(mPrefs.getBoolean(PREF_BOOL151, false));
		chbPapelToalha.setChecked(mPrefs.getBoolean(PREF_BOOL152, false));
		chbRodo.setChecked(mPrefs.getBoolean(PREF_BOOL153, false));
		chbSacodeLixo.setChecked(mPrefs.getBoolean(PREF_BOOL154, false));
		chbVassoura.setChecked(mPrefs.getBoolean(PREF_BOOL155, false));
		chbVela.setChecked(mPrefs.getBoolean(PREF_BOOL156, false));
		
		
		

		super.onResume();
		updateLoginStatus();
	}
	
	public void updateLoginStatus() {
		loginStatus.setText("Logged into Twitter : " + TwitterUtils.isAuthenticated(prefs));
	}
	
	private String getTweetMsg() {
		return "Tweeting from Android App";
	}	
	
	public void sendTweet() {
		Thread t = new Thread() {
	        public void run() {
	        	
	        	try {
	        		TwitterUtils.sendTweet(prefs,getTweetMsg());
	        		mTwitterHandler.post(mUpdateTwitterNotification);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
	        }

	    };
	    t.start();
	}
	
	@Override
	protected void onPause() {
		Editor e = mPrefs.edit();
		
		e.putBoolean(PREF_BOOL137, chbCopoDescartavel.isChecked());
		e.putBoolean(PREF_BOOL138, chbEsponja.isChecked());
		e.putBoolean(PREF_BOOL139, chbEsponjadeAco.isChecked());
		e.putBoolean(PREF_BOOL140, chbFilmePlastico.isChecked());
		e.putBoolean(PREF_BOOL141, chbFiltroCafe.isChecked());
		e.putBoolean(PREF_BOOL142, chbFlanela.isChecked());
		e.putBoolean(PREF_BOOL143, chbFosforo.isChecked());
		e.putBoolean(PREF_BOOL144, chbGuardanapo.isChecked());
		e.putBoolean(PREF_BOOL145, chbLampada.isChecked());
		e.putBoolean(PREF_BOOL146, chbLuvas.isChecked());
		e.putBoolean(PREF_BOOL147, chbPa.isChecked());
		e.putBoolean(PREF_BOOL148, chbPalito.isChecked());
		e.putBoolean(PREF_BOOL149, chbPanodeChao.isChecked());
		e.putBoolean(PREF_BOOL150, chbPanodePrato.isChecked());
		e.putBoolean(PREF_BOOL151, chbPapelAluminio.isChecked());
		e.putBoolean(PREF_BOOL152, chbPapelToalha.isChecked());
		e.putBoolean(PREF_BOOL153, chbRodo.isChecked());
		e.putBoolean(PREF_BOOL154, chbSacodeLixo.isChecked());
		e.putBoolean(PREF_BOOL155, chbVassoura.isChecked());
		e.putBoolean(PREF_BOOL156, chbVela.isChecked());

		e.commit();
		super.onPause();
	}

}
